🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators exists
Created by Alexandra on 2017-08-13 · Last edited by Vale.buyondo on 2025-12-11.

PurposeChecks whether any element in a collection satisfies a given condition.

Returns true if at least one element matches; otherwise, returns false.

Syntax

Collection->exists(variable | condition)


Collection a list, set, or other enumerable collection.

variable a placeholder name for each element in the collection.

condition a Boolean expression that each element is tested against.

Example

Customer.allInstances()->exists(o | o.name = 'John')

Checks if any Customer in the system has name = 'John'.

Returns true if at least one customer of name John exists.

Expression Result
Sequence{2.3, 5.2}->exists(self > 3) true


This is the reverse of ->forAll.